package com.hncboy.chatgpt.base.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hncboy.chatgpt.base.domain.entity.ChatCustomerDO;
import com.hncboy.chatgpt.base.mapper.ChatCustomerMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/****************************************
 * @name com.hncboy.chatgpt.base.task
 * @description
 * @author limi
 * @since 2023-04-21 21:53
 ***************************************/
@Slf4j
@Component
public class SchedulerTask {
    @Resource
    ChatCustomerMapper chatCustomerMapper;

    @Scheduled(cron = "0 0 0 * * ?")
    private void scheduled3() {
        QueryWrapper<ChatCustomerDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 0);
        List<ChatCustomerDO> chatCustomerDOS = chatCustomerMapper.selectList(queryWrapper);
        chatCustomerDOS.stream()
                .filter(chatCustomerDO -> chatCustomerDO.getLimits() < 5)
                .forEach(chatCustomerDO -> {
                    chatCustomerDO.setLimits(5);
                    chatCustomerMapper.updateById(chatCustomerDO);
                });
    }
}
